
/* JavaScript content from js/register-page.js in folder common */
(function($){
	$(document).bind("mobileinit", function() {
	    $.mobile.page.prototype.options.addBackBtn = true;
	});
	alert("does this happen");
	$("#registerSubmitBtn").on('click',function(){	
		if(getLoginStatus()){
			customerRegisterReq();
		}
		else{
			if(!focused[0]){
				$("#nameError").removeClass("hidden");
			}
			if(!focused[1]){
				$("#phoneError").removeClass("hidden");
			}
			if(!focused[2]){
				$("#pwdError").removeClass("hidden");
			}
			if(!focused[3]){
				$("#confirmPwdError").removeClass("hidden");
			}
		}
		//alert($("#canLogin").text());
	});
})(jQuery);

function customerRegisterReq() {
	var registerNickname = $('#registerNickname').val();
	var registerPsw = $('#registerPsw').val();
	var confirmPsw = $('#registerPsw2').val();
	var registerUname = $('#registerUname').val();
	var sex = $('input:radio[name=registerSex]:checked').val();
	var role = $('input:radio[name=registerRole]:checked').val();
//	if(!registerUname || !registerPsw || !registerPsw2 || !registerNickname) {
//		alert("Username, phone and password cannot be empty!");
//        return;
//	}	
//	if(registerPsw2 != registerPsw) {
//		alert("Password Not Match!");
//        return;
//	}
//	
//	if (!checkSubmitMobile()) {
//		alert("incorrect phone format");
//		$("#registerUname").val("");
//		$("#registerUname").focus();
//		return;
//	}
	//alert("pwd " + registerPsw);
	//alert("sex " + sex);
	//alert("role " + role);
	busy.show();
	var invocationData = {
			adapter : 'stAdp',
			procedure : 'registerReq',
			parameters : [{'kind':role, 'cus_phone': registerUname, 'cus_pwd':registerPsw,
				'sex':sex, 'nickname':registerNickname}]
		};
	
	WL.Client.invokeProcedure(invocationData,{
		timeout:20000,
		onSuccess : registerSuccess,
		onFailure : registerFailure
	});	
}
function registerSuccess(result) {
	//alert(result.invocationResult.status);
	busy.hide();
	if(result.invocationResult.status == 0){
		alert("register success!");
		$.mobile.changePage("../SmartTest7_17.html");
	}else if(result.invocationResult.status == 1){
		alert("phone is already exist!");	
	}else{		
		alert("system error");	
	}
}
function registerFailure(result) {
	busy.hide();
	alert("register request fail!");	
	WL.Logger.error("login request failure");
}

